﻿using System;
using System.Collections.Generic;
using NetBay.Core.BusinessEntities;

namespace Rio.Framework.Pages.Helpers
{
    /// <summary>
    /// Custom comparer for the Organization class
    /// </summary>
    public class OrganizationComparer : IEqualityComparer<Organization>
    {
        //Check whether the compared objects reference the same data.
        bool IEqualityComparer<Organization>.Equals(Organization x, Organization y)
        {
            //Check whether the compared objects reference the same data.
            if (Object.ReferenceEquals(x, y)) return true;

            //Check whether any of the compared objects is null.
            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;

            //Check whether the products' properties are equal.
            return x.Identifier == y.Identifier;
        }

        int IEqualityComparer<Organization>.GetHashCode(Organization obj)
        {
            //Check whether the object is null
            if (Object.ReferenceEquals(obj, null)) return 0;

            //Get hash code for the Name field if it is not null.
            int hashOragnizationIdentifier = obj.Identifier == null ? 0 : obj.Identifier.GetHashCode();

            //Get hash code for the Code field.
            int hashOrganizationCode = obj.Identifier.GetHashCode();

            //Calculate the hash code for the product.
            return hashOragnizationIdentifier ^ hashOrganizationCode;

        }
    }
}
